package com.github.lee.unsplash.ui.splash

import android.os.CountDownTimer
import androidx.lifecycle.MutableLiveData
import com.github.lee.mvvm.core.vm.BaseViewModel

private const val DELAY_TIME = 5 * 1000L

class SplashVM : BaseViewModel() {

    val timerLiveData = MutableLiveData<Long>()

    private val timer = object : CountDownTimer(DELAY_TIME, 1000) {
        override fun onTick(millisUntilFinished: Long) {
            timerLiveData.postValue(millisUntilFinished)
        }

        override fun onFinish() {
            timerLiveData.postValue(0L)
        }
    }


    override fun onCreate() {
        timer.start()
    }

    override fun onDestroy() {
        super.onDestroy()
        timer.cancel()
    }

}